//
//  searchView.m
//  garbageclient
//
//  Created by Wang Wu on 11-8-12.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "searchView.h"
#import "commondef.h"

@implementation searchView

@synthesize delegate;

- (void)dealloc
{
    [searchbar release];
    
    [super dealloc];
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        
        CGRect bounds = [[UIScreen mainScreen] applicationFrame];
        
        searchbar = [[UISearchBar alloc]initWithFrame:CGRectMake(0.0, 0.0, bounds.size.width, SEARCHBAR_HEIGHT)];
        searchbar.delegate = self;
        searchbar.placeholder = @"搜索";
        [self addSubview:searchbar];
        [searchbar becomeFirstResponder];
        searchbar.showsCancelButton = YES;
        
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/
#pragma mark searchbardegete
-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    [searchbar resignFirstResponder];
}

-(void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
{
    [searchbar resignFirstResponder];
}

-(void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
    bSearchbarEndEdit = NO;
}

-(void)searchBarTextDidEndEditing:(UISearchBar *)searchBar
{
    bSearchbarEndEdit = YES;
}

#pragma mark touch
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesBegan:touches withEvent:event];
    
    UITouch *touch = [touches anyObject];
    CGPoint location = [touch locationInView:self];
    
    CGRect screenrc = [[UIScreen mainScreen] applicationFrame];
    if(CGRectContainsPoint(CGRectMake(0.0, 
                                      20.0 + NAV_HEIGHT,
                                      screenrc.size.width, 
                                      screenrc.size.height - 20.0 - NAV_HEIGHT - 80.0),
                           location) && bSearchbarEndEdit)
    {
//        [delegate TurnView:DETAILS_VTP withDetailsBackTp:SEARCH_DBTP];
    }
}
@end
